package aishua.com.mytestapplist;

import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.InsetDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import java.util.ArrayList;

import aishua.com.mytestapplist.adapter.MyListViewAdapter;
import aishua.com.mytestapplist.adapter.RecycleViewAdapter;
import aishua.com.mytestapplist.adapter.RecycleViewDivider;
import aishua.com.mytestapplist.bean.ItemBean;
import aishua.com.mytestapplist.utils.LogUtils;

/**
 * Created by aishua on 2018/3/27.
 */

public class RecyleViewActivity extends Activity {
    private static final String TAG = "RecyleViewActivity-";
     private ListView lv_test;
     private RecyclerView recycle_test;
     private ArrayList<ItemBean> arrayList = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_layout);
        lv_test = (ListView) findViewById(R.id.lv_test);
        recycle_test = (RecyclerView) findViewById(R.id.recycle_test);
        initItemData();
        lv_test.setAdapter(new MyListViewAdapter(this,arrayList));
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getBaseContext(),
                LinearLayoutManager.VERTICAL, false);
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(getBaseContext(),3,LinearLayoutManager.VERTICAL,false);
//        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
         recycle_test.setLayoutManager(layoutManager);
         recycle_test.setItemAnimator(new DefaultItemAnimator());
         recycle_test.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.HORIZONTAL,2, Color.YELLOW));
        recycle_test.addItemDecoration(new MyRecycleViewDivider());
        recycle_test.setAdapter(new RecycleViewAdapter(this,arrayList));

    }
     public void initItemData(){

         ItemBean itemBean = new ItemBean();
         itemBean.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean.setFruitName("苹果");
         ItemBean itemBean1 = new ItemBean();
         itemBean1.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean1.setFruitName("梨子");
         ItemBean itemBean2 = new ItemBean();
         itemBean2.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean2.setFruitName("香蕉");
         ItemBean itemBean3 = new ItemBean();
         itemBean3.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean3.setFruitName("西瓜");
         ItemBean itemBean4 = new ItemBean();
         itemBean4.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean4.setFruitName("哈密瓜");
         ItemBean itemBean5 = new ItemBean();
         itemBean5.setFruitImg(R.drawable.quick_tour_generate_icon);
         itemBean5.setFruitName("橙子");
         arrayList.add(itemBean);
         arrayList.add(itemBean1);
         arrayList.add(itemBean2);
         arrayList.add(itemBean3);
         arrayList.add(itemBean4);
         arrayList.add(itemBean5);
         arrayList.add(itemBean);
         arrayList.add(itemBean1);
         arrayList.add(itemBean2);
         arrayList.add(itemBean3);
         arrayList.add(itemBean4);
         arrayList.add(itemBean5);
     }
    public class MyRecycleViewDivider extends RecyclerView.ItemDecoration{
        private Paint mPaint;
        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
            mPaint = new Paint();
            mPaint.setStyle(Paint.Style.FILL);
            mPaint.setColor(getResources().getColor(R.color.yellow));//画笔颜色
           c.drawArc(new RectF(0,300,300,100),0,0,true,mPaint);
        }

        @Override
        public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
            super.onDrawOver(canvas, parent, state);
//            mPaint.setColor(getResources().getColor(R.color.yellow));//画笔颜色
//            mPaint.setStyle(Paint.Style.FILL);
////            c.drawArc(new RectF(20,0,300,900),0,100,true,mPaint);
//            c.drawRect(new RectF(0,0,500,10),mPaint);
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.set(0, 0, 0, 0);
        }
    }
}
